SRC    :=  $(shell find . -iname '*.c' -o -iname '*.cpp')

OBJ := $(patsubst %.c,%.o, $(patsubst %.cpp,%.o, $(SRC))) 

LIB_VERSION = 2023070602

TARGET_PLATFORM =
SUFFIX=
CC =gcc
CXX = g++
AR = ar
STRIP = strip
#CFLAG = -DLINUX  -D_GNU_SOURCE -Wno-psabi -O2 -fPIC -std=c++11
CFLAG = -DLINUX  -D_GNU_SOURCE -Wno-psabi -O2 -fPIC -DSAVE_MP4 -DSAVE_VIDEO -DPARSE_VEIHCLE -D_GLIBCXX_USE_NANOSLEEP
CFLAG += -DUSE_TURBO_JPEG
CFLAG += -DPLAY_VIDEO
CFLAG += -DLIB_VERSION=\"$(LIB_VERSION)\"

CXXFLAG = $(CFLAG)
DEFAULT_LIB_INSTALL_PATH = .:./xlw_lib


BINPATH = ./bin$(SUFFIX)

LDFLAG = -lpthread -lrt -ldl -lHvdevice -lVideoSaver_ff -lH264_linux
LDFLAG += -lturbojpeg
LDFLAG += -Wl,-rpath,$(DEFAULT_LIB_INSTALL_PATH)

INC = -I.\
	-I./Plugins \
	-I./Plugins/customFuncHelper \
	-I./Plugins/deleterHelper \
	-I./Plugins/dirHelper \
	-I./Plugins/initReader \
	-I./Plugins/logHelper \
	-I./Plugins/netHelper \
	-I./Plugins/plateHelper \
	-I./ugins/stringHelper \
	-I./Plugins/threadHelper \
	-I./Plugins/timeHelper \
	-I./Plugins/tinyXml \
	-I./cameraModule \
	-I./Common \
	-I./libHvDevice_linux \
	-I/home/huma/tool/libjpeg-turbo-1.4.2/X86_64/include



NAME_LINKER = libHGCamera.so
VERSION_MAJOR = 2.0
VERSION_MINOR = 0.1
NAME_SO = $(NAME_LINKER).$(VERSION_MAJOR)
NAME_REAL = $(NAME_LINKER).$(VERSION_MAJOR).$(VERSION_MINOR)

PROGRAM = $(NAME_REAL)	
StaticLib = libVLPR_JX_GB.a

VERSION_CONTRL = -Wl,-soname,$(NAME_SO) -o $(NAME_REAL)

X86:SUFFIX += _x86
X86:LIBPATH = -L./lib$(SUFFIX)
X86:LIBPATH += -L/home/huma/winShare/ffmpeg-4.2.4/ffmpeg-4.2.4/build/lib
X86:LIBPATH += -L/home/huma/tool/libVideoSaver_ff_ffmpeg4.2.4
X86:LIBPATH += -L/home/huma/tool/libH264_linux_ffmpeg_4.2.4
X86:LIBPATH += -L/home/huma/tool/SDL2-2.0.12/lib
X86:CFLAG += -g
X86:CFLAG += -std=gnu++0x
X86:CXXFLAG = $(CFLAG)
X86:$(PROGRAM)


X64:SUFFIX += _x64
# x64:INC +=-I /home/huma/tool/libjpeg-turbo-1.4.2/X86_64/include
X64:LIBPATH = -L./lib$(SUFFIX)
X64:LIBPATH += -L/home/huma/tool/libHvdevice/x86_64
X64:LIBPATH += -L/home/huma/tool/libH264_linux_ffmpeg4.2.4/X86_64
X64:LIBPATH += -L/home/huma/tool/libVideoSaver_ff_ffmpeg4.2.4/x86_64
X64:LIBPATH += -L/home/huma/tool/libjpeg-turbo-1.4.2/X86_64/lib
X64:CFLAG += -std=gnu++0x
X64:CFLAG += -g
X64:CXXFLAG = $(CFLAG)
X64:$(PROGRAM)

_ARM:SUFFIX += _arm
_ARM:TARGET_PLATFORM += arm-none-linux-gnueabi-
_ARM:CFLAG += -std=gnu++0x
_ARM:CXXFLAG = $(CFLAG)
_ARM:$(PROGRAM)

#debug version
debug:	CFLAG += -g
debug:  CFLAG += -std=gnu++0x
debug:	CXXFLAG = $(CFLAG)
debug:	$(PROGRAM)

#release version
release:CFLAG += -std=gnu++0x
release:$(PROGRAM)


Q =
w =
# W = -w

.c.o:
	@echo "Compile $@"
	$(Q)$(TARGET_PLATFORM)$(CC) $(CFLAG) -fPIC -o $@ -c $< $(INC) $(W)

.cpp.o:
	@echo "Compile $@"
	$(Q)$(TARGET_PLATFORM)$(CXX) $(CXXFLAG) -fPIC -o $@ -c $< $(INC) $(W)
	
	
$(PROGRAM):$(OBJ)
	$(Q)$(TARGET_PLATFORM)$(CXX) -shared $(VERSION_CONTRL) $(OBJ) $(LIBPATH) $(LDFLAG) -fvisibility=hidden 
#	$(Q)rm *.o
	$(Q)mkdir -p $(BINPATH)
	$(Q)cp $@ $(BINPATH)/$@

clean:
	$(Q)rm -rf $(PROGRAM) $(BINPATH)/$(PROGRAM) $(OBJ) 
